import axios from 'axios';

// 定义更精确的接口返回数据类型
interface TemperaturePrediction {
    date: string;
    average_temperature: number;
    day_of_week?: string;
    day_of_year?: number;
}

interface LSTMPredictionResponse {
    status: string;
    model: string;
    predictions: TemperaturePrediction[];
    plot_url?: string;
    last_training_date?: string;
    execution_time?: string;
    statistics?: {
        average: number;
        max: number;
        min: number;
    };
    prediction_days?: number;
    target_column?: string;
}

// 获取温度预测数据的函数（LSTM模型）
export async function fetchLSTMTemperaturePredictions(): Promise<LSTMPredictionResponse> {
    try {
        const response = await axios.get<LSTMPredictionResponse>(
            'http://127.0.0.1:5000/api/predict_lstm'
        );

        return response.data;
    } catch (error) {
        console.error('获取LSTM温度预测数据失败:', error);
        throw error;
    }
}

// 使用示例
async function exampleUsage() {
    try {
        const result = await fetchLSTMTemperaturePredictions();
        console.log('预测结果:', result);

        if (result.status === 'success') {
            console.log('最近预测:', result.predictions.slice(0, 5));
            console.log('平均温度:', result.statistics?.average);
        }
    } catch (error) {
        console.error('请求处理失败:', error);
    }
}  